package com.voa.service;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.team4.dao.DAOFactory;
import org.team4.exception.CRUDException;
import org.team4.service.IService;
import org.team4.util.LoginBean;
import org.team4.vo.Page;

import com.voa.constants.OASQLConstant;
import com.voa.dao.BlogTagsDAO;
import com.voa.domain.BlogTags;

/**
 * <p>程序名称：       BlogService.java</p>
 * <p>程序说明：       日志标签服务</p>
 * <p>版权信息：       Copyright 深圳市维远泰克科技有限公司</p>
 * <p>时间：          Feb 11, 2011 11:39:08 AM</p>	
 * 
 * @author：          Marker.King
 * @version：         Ver 0.1
 */
@Service
public class BlogTagsService implements IService {

	private BlogTagsDAO blogTagsDAO;
	
	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		blogTagsDAO = (BlogTagsDAO) DAOFactory.getDAO(sessionFactory, BlogTagsDAO.class);
	}

	public Page<BlogTags> listPagination(Page<BlogTags> page) throws CRUDException {
		return blogTagsDAO.pagination(page, OASQLConstant.BLOGTAGS_BY_CREATOR, null, LoginBean.getLoginBean().getUser());
	}
	
	public List<BlogTags> findOwnBlogTags() throws CRUDException {
		return blogTagsDAO.findByProperty("creator", LoginBean.getLoginBean().getUser());
	}
	
	public BlogTags findBlogTagsById(String id) throws CRUDException {
		return blogTagsDAO.get(id);
	}
	
	public void saveBlogTags(BlogTags blogTags) throws CRUDException {
		blogTags.setCreator(LoginBean.getLoginBean().getUser());
		blogTagsDAO.save(blogTags);
	}
	
	public void updateBlogTags(BlogTags blogTags) throws CRUDException {
		BlogTags old = blogTagsDAO.get(blogTags.getId());
		old.setColor(blogTags.getColor());
		old.setName(blogTags.getName());
		blogTagsDAO.update(old);
	}
	
	public void deleteBlogTags(List<String> idList) throws CRUDException {
		blogTagsDAO.deleteByIdList(idList);
	}
}
